package com.roamer.audition.server.entity.base;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;


/**
 * 逻辑删除
 *
 * @author roamer
 * @version V1.0
 * @date 2019-07-16 11:01
 */
@MappedSuperclass

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public abstract class LogicDeleteBaseEntity extends BaseEntity {
    private static final long serialVersionUID = 7156642299317773804L;

    /** 删除标记 */
    @Column(name = "is_deleted", nullable = false, columnDefinition = "bit default 0 comment '删除标记'")
    protected Boolean deleted;

    protected LogicDeleteBaseEntity(Long id, Long version, Long createTime, Long updateTime, Boolean deleted) {
        super(id, version, createTime, updateTime);
        this.deleted = deleted;
    }

    @Override
    @PrePersist
    public void prePersist() {
        super.prePersist();
        if (deleted == null) {
            deleted = Boolean.FALSE;
        }
    }

}
